//
//  DDChatJobCell.m
//  DingDongZP
//
//  Created by 杨政涛 on 16/8/4.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

#import "DDChatJobCell.h"

@implementation DDChatJobCell


- (void)updateJobDetailCellWithInfo:(DDJobsDetail *)detailInfo
{
    self.jobTitleLabel.text = !detailInfo.jobtitle?@"职位名称":detailInfo.jobtitle;
    
    self.salaryLabel.text = [NSString stringWithFormat:@"￥%@",!detailInfo.salary?@"薪资":detailInfo.salary];
    self.jobLabel.attributedText = [DDUtils image:@"icon_position" imageWidth:10 imageHeight:12 ContentText:!detailInfo.category?@"职位类型":detailInfo.category];
    
    self.cityLabel.attributedText = [DDUtils image:@"icon_address" imageWidth:12 imageHeight:12 ContentText:!detailInfo.city?@"城市":detailInfo.city];
    self.experienceLabel.attributedText = [DDUtils image:@"icon_experience" imageWidth:12 imageHeight:12 ContentText:!detailInfo.experience?@"经验":detailInfo.experience];
    self.eduLabel.attributedText = [DDUtils image:@"icon_education" imageWidth:12 imageHeight:12 ContentText:!detailInfo.edu?@"学历":detailInfo.edu];
    
    self.bossPositionLabel.text = [NSString stringWithFormat:@"Boss职位: %@",!detailInfo.position?@"未填写":detailInfo.position];
    self.companyLabel.text = [NSString stringWithFormat:@"公司: %@",!detailInfo.companyfullname?@"未填写":detailInfo.companyfullname];
    
    NSString *iconurl = [DDAPIGenerate imageURLWithPath:detailInfo.logo];
    [self.bossImage sd_setImageWithURL:[NSURL URLWithString:iconurl] placeholderImage:[UIImage imageNamed:@"default_header"]];
    self.bossName.text = !detailInfo.employername?@"姓名":detailInfo.employername;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.jobTitleLabel = [[UILabel alloc]init];
    self.jobTitleLabel.textColor = COLOR_FONT_MAIN_GREEN;
    self.jobTitleLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:self.jobTitleLabel];
    WEAKSELF
    self.bossImage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.bossImage];
    [self.bossImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(weakSelf).offset(25);
        make.right.equalTo(weakSelf).offset(-20);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    self.bossImage.layer.masksToBounds = YES;
    self.bossImage.layer.cornerRadius = 60/2;
    
    self.bossName = [[UILabel alloc]init];
    self.bossName.textColor = COLOR_FONT_DARK_GRAY;
    self.bossName.font = [UIFont systemFontOfSize:14];
    self.bossName.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.bossName];
    [self.bossName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bossImage.mas_bottom).offset(10);
        make.width.equalTo(self.bossImage.mas_width);
        make.centerX.equalTo(self.bossImage.mas_centerX);
    }];
    
    
    [self.jobTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(weakSelf).offset(15);
        make.left.equalTo(weakSelf).offset(15);
        make.right.equalTo(self.bossImage.mas_left).offset(-10);
    }];
    
    self.salaryLabel = [[UILabel alloc]init];
    self.salaryLabel.textColor = COLOR_FONT_RED;
    self.salaryLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.salaryLabel];
    [self.salaryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.jobTitleLabel.mas_bottom).offset(10);
        make.left.equalTo(weakSelf).offset(15);
    }];
    
    self.jobLabel = [[UILabel alloc]init];
    self.jobLabel.textColor = COLOR_FONT_DARK_GRAY;
    self.jobLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.jobLabel];
    [self.jobLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.salaryLabel.mas_top);
        make.left.equalTo(self.salaryLabel.mas_right).offset(10);
    }];
    
    self.cityLabel = [[UILabel alloc]init];
    self.cityLabel.textColor = COLOR_FONT_DARK_GRAY;
    self.cityLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.cityLabel];
    [self.cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.salaryLabel.mas_bottom).offset(10);
        make.left.equalTo(weakSelf).offset(15);

    }];
    
    self.experienceLabel = [[UILabel alloc]init];
    self.experienceLabel.textColor = COLOR_FONT_DARK_GRAY;
    self.experienceLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.experienceLabel];
    [self.experienceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.cityLabel.mas_top);
        make.left.equalTo(self.cityLabel.mas_right).offset(10);
    }];
    
    self.eduLabel = [[UILabel alloc]init];
    self.eduLabel.textColor = COLOR_FONT_DARK_GRAY;
    self.eduLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.eduLabel];
    [self.eduLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.cityLabel.mas_top);
        make.left.equalTo(self.experienceLabel.mas_right).offset(10);
    }];
    
    self.bossPositionLabel = [[UILabel alloc]init];
    self.bossPositionLabel.textColor = COLOR_FONT_DARK_GRAY;
    self.bossPositionLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.bossPositionLabel];
    [self.bossPositionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.cityLabel.mas_bottom).offset(10);
        make.left.equalTo(weakSelf).offset(15);
        make.right.equalTo(self.bossImage.mas_left).offset(-10);
    }];
    
    self.companyLabel = [[UILabel alloc]init];
    self.companyLabel.textColor = COLOR_FONT_DARK_GRAY;
    self.companyLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.companyLabel];
    [self.companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bossPositionLabel.mas_bottom).offset(10);
        make.left.equalTo(weakSelf).offset(15);
        make.right.equalTo(weakSelf).offset(-15);
    }];
    
}


- (NSAttributedString *)string:(NSString *)string withIcon:(UIImage *)icon
{
    if (string == nil || icon == nil) {
        return [NSAttributedString new];
    }
    NSMutableAttributedString *titleAttributed = [[NSMutableAttributedString alloc] initWithString:string];
    [titleAttributed addAttribute:NSForegroundColorAttributeName
                            value:COLOR_FONT_DARK_GRAY
                            range:NSMakeRange(0,string.length)];
    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    textAttachment.image = icon;
    
    textAttachment.bounds = CGRectMake(0, 0,12,12);
    [titleAttributed insertAttributedString:[NSAttributedString attributedStringWithAttachment:textAttachment] atIndex:0];
    [titleAttributed insertAttributedString:[[NSAttributedString alloc] initWithString:@" "] atIndex:1];
    return titleAttributed;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
